/*
 * All rights Reserved, Designed By DataDriver
 * Copyright:    DataDriver.Inc
 * Company:      Zhuo Wo Infomation Technology (ShangHai) CO.LTD
 */
package com.sun.cloudpayment.controller;

import com.sun.cloudapicommon.entity.SysUser;
import com.sun.cloudpayment.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @Resource
    private DiscoveryClient discoveryClient;

    @RequestMapping("/list")
    public List<SysUser> findAll() {
        List<SysUser> userList = sysUserService.findAll();
        System.out.println("8001...........................");
        return userList;
    }

    @RequestMapping("/discover")
    public Object discover() {
        //获取服务列表
        List<String> services = discoveryClient.getServices();
        for (String service : services) {
            System.out.println("当前服务名称为:" + service);
        }

        //获取实例列表
        List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PAYMENT-SERVER");
        for (ServiceInstance instance : instances) {
            System.out.println("主机:" + instance.getHost() + "..端口:" + instance.getPort());
        }

        return this.discoveryClient;
    }
}
